package cn.lx.auth.secutity.utils;

import cn.hsa.hsaf.core.framework.context.HsafContext;
import cn.hsa.hsaf.core.framework.context.HsafContextHolder;
import cn.hsa.hsaf.core.framework.context.impl.HsafContextImpl;
import cn.hsa.hsaf.core.framework.util.CurrentUser;
import cn.lx.auth.secutity.entity.PortalUserDetails;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @ClassName SessionToUserUtil
 * @Description: //todo
 * @Author: 落雪
 * @CreateDate: 2025/7/14 23:26
 * @UpdateUser: 落雪
 * @UpdateDate: 2025/7/14 23:26
 * @UpdateRemark:
 * @Version: 1.0
 */
public class SessionToUserUtil {
    private static final Log LOGGER = LogFactory.getLog(SessionToUserUtil.class);

    public SessionToUserUtil() {
    }

    public void toCurrentUser(PortalUserDetails userDetalis) {
        HsafContext hsafContext = new HsafContextImpl();
        CurrentUser currentUser = new CurrentUser();

        try {
            currentUser.setUserAcctID(userDetalis.getUactID());
            currentUser.setUserAcct(userDetalis.getUserAcct());
            currentUser.setUactID(userDetalis.getOpterNo());
            currentUser.setName(userDetalis.getName());
            currentUser.setOrgUntID(userDetalis.getOrgUntID());
            currentUser.setOrgName(userDetalis.getOrgName());
            currentUser.setOrgCodg(userDetalis.getOrgCodg());
            currentUser.setPoolAreaCodg(userDetalis.getPoolAreaCodg());
            currentUser.setAdmDvs(userDetalis.getAdmDvs());
            currentUser.setPrntOrgID(userDetalis.getPrntOrgID());
            currentUser.InsuTypePoolAreaMap = userDetalis.getInsuTypePoolAreaMap();
            currentUser.setDeptID(userDetalis.getDeptID() == null ? "" : userDetalis.getDeptID());
            currentUser.setDeptName(userDetalis.getDeptName() == null ? "" : userDetalis.getDeptName());
        } catch (Exception var5) {
            LOGGER.error(var5.toString(), var5);
        }

        hsafContext.setCurrentUser(currentUser);
        HsafContextHolder.setContext(hsafContext);
    }

    public void toMockUser() {
        HsafContext hsafContext = new HsafContextImpl();
        CurrentUser currentUser = new CurrentUser();

        try {
            currentUser.setUserAcctID("1");
            currentUser.setUserAcct("mockuser");
            currentUser.setUactID("1");
            currentUser.setName("测试用户");
            currentUser.setOrgUntID("1001");
            currentUser.setOrgName("测试机构");
            currentUser.setOrgCodg("1100");
            currentUser.setPoolAreaCodg("2101");
            currentUser.setAdmDvs("2100");
            currentUser.setPrntOrgID("-1");
            currentUser.setDeptID("1010");
            currentUser.setDeptName("测试部门");
        } catch (Exception var4) {
            LOGGER.error(var4.toString(), var4);
        }

        hsafContext.setCurrentUser(currentUser);
        HsafContextHolder.setContext(hsafContext);
    }
}

